package com.briup.pts.service.impl;

import com.briup.pts.mapper.QrcodeMapper;
import com.briup.pts.service.QrcodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class QrcodeServiceImpl implements QrcodeService {

    private final QrcodeMapper qrcodeMapper;

    @Override
    @Transactional
    public void addQrcode(String animalId, String url) {
        // 注意为了保证一头动物只能有一个二维码，那么在添加之前先删除该动物对应的二维码数据
        deleteByAnimalId(animalId);
        // 删除后在继续添加
        qrcodeMapper.addQrcode(animalId,url);
    }

    @Override
    public void deleteByAnimalId(String animalId) {
        qrcodeMapper.deleteByAnimalId(animalId);
    }
}
